package ro.prjmanager.core.context;

import org.directwebremoting.util.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * TeamnetWebContextBuilder.java Copyright (c) 2009 Teamnet. All Rights Reserved. This source file
 * may not be copied, modified or redistributed, in whole or in part, in any form or for any reason,
 * without the express written consent of Teamnet.
 */
@SuppressWarnings("unchecked")
public class PrjManagerWebContextBuilder implements ApplicationContextFactory.WebContextBuilder {
    public static PrjManagerWebContextBuilder getBuilder(){
        return new PrjManagerWebContextBuilder();
    }

    public void set(HttpServletRequest request, HttpServletResponse response) {
         try
        {
            WebContext ec = new WebContextFactoryImpl(request, response);
            user.set(ec);
        }
        catch (Exception ex)
        {
            log.fatal("Failed to create an ExecutionContext", ex);
        }
    }

    public WebContext get() {
        return (WebContext) user.get();
    }

    public void unset() {
         user.set(null);
    }


    /**
     * The storage of thread based data
     */
    private static ThreadLocal user = new ThreadLocal();

    /**
     * The log stream
     */
    private static final Logger log = Logger.getLogger(PrjManagerWebContextBuilder.class);
}
